<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

define("EMPTY", " - ");
class Dashboard extends CI_Controller {

	//Doctrine EntityManager
	public $em;

	function __construct() {
		parent::__construct();

		//Not required if you autoload the library
		$this -> load -> library('doctrine');

		//Instantiate a Doctrine Entity Manager
		$this -> em = $this -> doctrine -> em;
		// $conn = $this->em->getConnection();
		//var_dump(models\service\CurrentUser::user());
		if (models\service\CurrentUser::user() == FALSE){
			header('location: ' . base_url());
		}

		// $conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'varchar');
	}
	
	public function manager(){

		$user = models\service\CurrentUser::user();
		$criteria = array('userId' => $user->getUserId());
		$userProfiles = $this->em->getRepository('\models\entities\UserProfile')->findBy($criteria);

		$data['breadcrumb'] = array( array("label" => "Home", "link" => base_url() . "dashboard/manager")
								);
		$data['userProfiles'] = $userProfiles;
		$data['user'] = $user; 		
		$data['jumlahFinalBerkas'] = $this->em->getRepository('\models\entities\Berkas')->findNumberFinalBerkas();
		$data['jumlahCFBerkas'] = $this->em->getRepository('\models\entities\Berkas')->findNumberCFBerkas();
		$data['jumlahDQABerkas'] = $this->em->getRepository('\models\entities\Berkas')->findNumberDQABerkas();
		$data['jumlahCBOBerkas'] = $this->em->getRepository('\models\entities\Berkas')->findNumberCBOBerkas();
		$data['jumlahMEBerkas'] = $this->em->getRepository('\models\entities\Berkas')->findNumberMEBerkas();
		$data['initProfile'] = $userProfiles[0]->getProfile()->getId();
		
		$this->load->view('dashboard/manager', $data);		
	}

	public function managerCf(){

		$user = models\service\CurrentUser::user();
		$criteria = array('userId' => $user->getUserId());
		$userProfiles = $this->em->getRepository('\models\entities\UserProfile')->findBy($criteria);

		$data['breadcrumb'] = array( array("label" => "Home", "link" => base_url() . "dashboard/managerCf")
								);
		$data['userProfiles'] = $userProfiles;
		$data['user'] = $user; 		
		$data['jumlahDraft'] = $this->em->getRepository('\models\entities\Berkas')->findNumberCFBerkasByUser($user->getUserId());
		$data['jumlahProgress'] = $this->em->getRepository('\models\entities\Berkas')->findNumberCFBerkasProgressByUser($user->getUserId());
		$data['jumlahFinal'] = $this->em->getRepository('\models\entities\Berkas')->findNumberFinalBerkasByUser($user->getUserId());
		$data['initProfile'] = $userProfiles[0]->getProfile()->getId();
		
		$this->load->view('dashboard/managerCf', $data);		
	}
	
}

